<?php
/**
 * 
 * controller for base
 * ThankPHP framework
 * 
 * @author etongchina <etongchina@gmail.com>
 * @versioin 0.1
 */

if(!defined('IN_THANKPHP_SYSTEM')) exit('Access Denied!');

/**
 * controller for base
 *
 * @package controller
 * @static bool $FLAG
 * @
 */
abstract class controller extends base {
	static $FLAG = false;
	public $view,$model,$urls;
	private	$class_name;
	private $tpl;
	
	public function checkFunc($func){
		if(!method_exists($this, $func)){
			return false;
		}
		return true;
	}
	
	public function dispatcher(){
		global $DEBUG;
		$this->view->dispatcher();
		if($DEBUG)
		print 'controller dispatch begin......<br/>';
	}
	
	abstract function getVo();
	public function set_classname($name){
		$this->class_name = $name;
	}
	
	public function getTpl(){
		return $this->tpl.".php";
	}

	public function getInstance(){
		if(self::$FLAG){
			return self;
		}else{
			self::$FLAG = true;
			return new self();
		}
	}
	
	public function init(){
		global $DB;
		$classname_v = $this->class_name.'_view';
		$this->view = new $classname_v;
		$this->model = $DB;
	}
	
	public function setTpl($tpl){
		$this->tpl = $tpl;
		return $this;
	}
	
	public function show(){
		$this->init();
		$this->get_vo();
		$this->view->show();
	}
}